package com.itheima.utils;

import generator.pojo.Employee;
import org.apache.ibatis.session.SqlSession;
import org.junit.jupiter.api.Test;

public class EmployeeTest {
    @Test
    public void findEmployeeByIdTest(){
        SqlSession sqlSession =  MybatisUtils.getSession();
        Employee employee = sqlSession.selectOne("selectByPrimaryKey",3L);
        System.out.println(employee.toString());
        sqlSession.commit();
        sqlSession.close();
    }
    @Test
    public void addEmployeeTest(){
        SqlSession sqlSession = MybatisUtils.getSession();
        Employee employee = new Employee();
        employee.setId(4);
        employee.setName("赵六");
        employee.setAge(16);
        employee.setPosition("临时工");

        int addInt= sqlSession.insert("insert",employee);
        System.out.println(addInt);
        sqlSession.commit();
        sqlSession.close();
        System.out.println(addInt);
    }
    @Test
    public void updateEmployeeTest(){
        SqlSession sqlSession = MybatisUtils.getSession();
        Employee employee = new Employee();
        employee.setId(2);
        employee.setName("赵六");
        employee.setAge(16);
        employee.setPosition("临时工");
          int u= sqlSession.update("updateByPrimaryKey",employee);
        sqlSession.commit();
        sqlSession.close();
        System.out.println(u);
    }
    @Test
    public void deleteEmployeeById(){
        SqlSession sqlSession = MybatisUtils.getSession();
        int d = sqlSession.delete("deleteByPrimaryKey",1L);
        sqlSession.commit();
        sqlSession.close();
        System.out.println(d);
    }
}
